package com.java3_21;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo1 {

//    public void Print(){
//        synchronized (this){
//            System.out.println("外部");
//            synchronized (this){
//                System.out.println("中部");
//                synchronized (this){
//                    System.out.println("内部");
//                }
//            }
//        }
//    }

    Lock lock = new ReentrantLock();
    public void Print(){
        lock.lock();
        try {
            System.out.println("外部");
            lock.lock();
            try {
                System.out.println("中部");
                lock.lock();
                try {
                    System.out.println("内部");
                }finally {
                    lock.unlock();
                }
            }finally {
                lock.unlock();
            }
        }finally {
            lock.unlock();
        }
    }
}
